package jobPerCity;

import org.apache.commons.io.output.NullWriter;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import Bean.JobPerCityBean;
import partition.JobBeanPartitioner;

public class JobPerCityDriver {

    public static void main(String[] args) throws Exception {
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        job.setJarByClass(JobPerCityDriver.class);

        job.setMapperClass(JobPerCityMapper.class);
        job.setReducerClass(JobPerCityReducer.class);

        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(JobPerCityBean.class);

        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWriter.class);

        //参考<=Partitioner里面的字典数+1（多出来一个放其它不在字典里面的）
        job.setNumReduceTasks(8);
        job.setPartitionerClass(JobBeanPartitioner.class);

        Path inputPath = new Path("input/jobData.csv");
        Path outputPath = new Path("output/JobPerCity");

        FileInputFormat.addInputPath(job,inputPath);
        FileOutputFormat.setOutputPath(job,outputPath);

        FileSystem fs = FileSystem.get(conf);
        if ( fs.exists(outputPath) ){
            fs.delete(outputPath,true);
        }


        System.exit(job.waitForCompletion(true) ? 0 : 1);
    }
}
